﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TDgame_TuretBase : MonoBehaviour
{
    public GameObject[] turetObjs;
    private GameObject hadTuret = null;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void BuillTuret()
    {
        //print(0);
        if (hadTuret == null)
        {
            //print(1);
            hadTuret = Instantiate(turetObjs[0], transform.position, transform.rotation);
        }else
        {
            //print(2);
            LevelUpTuret();
        }
    }

    public void LevelUpTuret() 
    {
        
        if (hadTuret!=null)
        {
            for (int i = 0; i < turetObjs.Length; i++)
            {
                //print(turetObjs[i].name);
                //print(hadTuret.name);
                if ((turetObjs[i].name+"(Clone)").Equals(hadTuret.name)&&i+1<turetObjs.Length)
                {
                    //print(3);
                    Destroy(hadTuret);
                    hadTuret = Instantiate(turetObjs[i + 1], transform.position, transform.rotation);
                    break;
                }
            }
        }
    }

    public void ClearTuret()
    {

        if (hadTuret != null)
        {
            Destroy(hadTuret);
            hadTuret = null;
        }
    }
}
